package com.example.musicplayer.bean;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;

import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.List;

public class Album  implements Serializable {
    private String name;
    private int number;
    private List<Song> songList;
    private byte[] albumCover;

    public Album() {
    }

    public Bitmap getAlbumCover() {
        if (albumCover.length != 0) {
            return BitmapFactory.decodeByteArray(albumCover, 0, albumCover.length);
        } else {
            return null;
        }
    }

    public void setAlbumCover(Bitmap albumCover) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        albumCover.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] data = baos.toByteArray();
        this.albumCover = data;
    }

    public Album(String name, int number, List<Song> songList, Bitmap albumCover) {
        this.name = name;
        this.number = number;
        this.songList = songList;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        albumCover.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] data = baos.toByteArray();
        this.albumCover = data;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public List<Song> getSongList() {
        return songList;
    }

    public void setSongList(List<Song> songList) {
        this.songList = songList;
    }
}
